<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="6" :md="8" :sm="24">
            <a-form-item label="房间号">
              <a-input placeholder="请输入房间号" v-model="queryParam.roomId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="6" :md="8" :sm="24">
            <a-form-item label="表类型">
              <a-select v-model="queryParam.type" placeholder="全部类型">
                <a-select-option :value="item.meterType" v-for="(item, index) in meterTypeUl" :key="index">{{ item.typeName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="6" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--工具栏-->
    <div class="head-container">
      <a-button v-permission="permission.add" class="filter-item" type="primary" icon="plus" @click="crudCreate" >新增</a-button>
    </div>
    <!--表格渲染-->
    <a-table
      size="middle"
      row-key="id"
      :columns="columns"
      :data-source="tableData"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change="handleTableChange"
    >
      <!--操作-->
      <span slot="action" slot-scope="text, record" >
        <a-button type="primary" @click="handleDetail(record)">详情</a-button>
        <a-button type="primary" @click="crudUpdate(record)">编辑</a-button>
        <a-popconfirm title="确认删除?" ok-text="确定" cancel-text="取消" @confirm="crudDelete(record.id)">
          <a-button type="danger" icon="delete"></a-button>
        </a-popconfirm>
      </span>
      <!--图片预览块-->
      <span slot="imgPath" slot-scope="text, record">
        <img :src="record.img" width="100px" height="100px" />
      </span>
    </a-table>
    <!--表单组件-->
    <demo-update-modal ref="updateForm" @closeModal="closeModal"></demo-update-modal>
  </div>
</template>

<script>
// xiao - chuanyue -- you di you -- baxinqiubianchenshenmti
// import moment from 'moment'
import ApiTree from '@/api/demo/demo';
import { Slime, crud } from '@/mixins/slime';
import demoUpdateModal from './modules/demoUpdateModal';

export default {
  name: 'Demo',
  components: { demoUpdateModal },
  mixins: [Slime],
  // 设置数据字典
  // dicts: ['dept_status'],
  data() {
    return {
      meterTypeUl: [
        { typeName: '电表', meterType:1 },
        { typeName: '水表', meterType:2 },
        { typeName: '热水表', meterType:3 },
      ],
      // table
      tableData: [
        {id:1, name:'陈事实', img:'https://dss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3228549874,2173006364&fm=26&gp=0.jpg', mobile:'15967125243'}
      ],
      columns: [
        {
          title: '名称',
          align: 'left',
          dataIndex: 'name',
        },
        {
          title: '图片',
          align: 'center',
          dataIndex: 'img',
          scopedSlots: { customRender: 'imgPath' },
        },
        {
          title: '电话',
          align: 'left',
          dataIndex: 'mobile',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 权限
      // permission: {
      //   add: ['admin', 'dept:add'],
      //   edit: ['admin', 'dept:edit'],
      //   del: ['admin', 'dept:del'],
      // },
    };
  },
  created() {
    crud(ApiTree)
    this.loadData();
  },
  methods: {
    // 加载表格数据
    loadData(arg) {
      this.loadDataPack(arg).then((res) => {
        let tableData = []
        if (res.result) {
          tableData = res.result.records;
        }
        this.tableData = tableData;
      });
    },
    handleDetail(){
      this.$router.push({ path: '/saleDetail?id=' + record.id + '&type=1'})
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>